package com.xianyun.site.iblog.user.executor;

import com.alibaba.cola.catchlog.CatchAndLog;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.xianyun.common.core.domain.TokenContent;
import com.xianyun.common.security.common.TokenConfig;
import com.xianyun.site.iblog.api.user.SystemUserServiceI;
import com.xianyun.site.iblog.co.user.SystemUserCO;
import com.xianyun.site.iblog.dto.user.*;
import com.xianyun.site.iblog.user.executor.command.SystemUserAddCmdExo;
import com.xianyun.site.iblog.user.executor.command.SystemUserUpdateCmdExo;
import com.xianyun.site.iblog.user.executor.command.UserNameChangeCmdExo;
import com.xianyun.site.iblog.user.executor.command.UserPasswordChangeCmdExo;
import com.xianyun.site.iblog.user.executor.query.SystemUserInfoQryExo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 系统服务接口实现 服务层
 * @author mac_zyj
 */
@Service
@CatchAndLog
public class SystemUserServiceImpl implements SystemUserServiceI {
    private static final String MODEL = "用户";
    @SuppressWarnings("all")
    @Autowired
    private TokenConfig tokenConfig;

    @Autowired
    private SystemUserAddCmdExo systemUserAddCmdExo;

    @Autowired
    private SystemUserUpdateCmdExo systemUserUpdateCmdExo;

    @Autowired
    private SystemUserInfoQryExo systemUserInfoQryExo;

    @Autowired
    private UserNameChangeCmdExo userNameChangeCmdExo;

    @Autowired
    private UserPasswordChangeCmdExo userPasswordChangeCmdExo;

    @Override
    public SingleResponse<SystemUserCO> getSystemUserInfoByToken(SystemUserInfoQry systemUserInfoQry) {
        TokenContent tokenContent=tokenConfig.checkToken(systemUserInfoQry.getToken(),systemUserInfoQry.getSessionId(),MODEL,true);
        systemUserInfoQry.setUid(tokenContent.getUid());
        return systemUserInfoQryExo.execute(systemUserInfoQry);
    }

    @Override
    public Response registerUser(SystemUserAddCmd cmd) {
        return systemUserAddCmdExo.execute(cmd);
    }

    @Override
    public Response updateUserInfo(SystemUserUpdateCmd cmd) {
        TokenContent tokenContent=tokenConfig.checkToken(cmd.getToken(),cmd.getSessionId(),MODEL,true);
        cmd.setUid(tokenContent.getUid());
        return systemUserUpdateCmdExo.execute(cmd);
    }

    @Override
    public Response updateUserName(UserNameChangeCmd cmd) {
        TokenContent tokenContent=tokenConfig.checkToken(cmd.getToken(),cmd.getSessionId(),MODEL,true);
        cmd.setUid(tokenContent.getUid());
        return userNameChangeCmdExo.execute(cmd);
    }

    @Override
    public Response changeUserPassword(UserPasswordChangeCmd cmd) {
        TokenContent tokenContent=tokenConfig.checkToken(cmd.getToken(),cmd.getSessionId(),MODEL,true);
        cmd.setUid(tokenContent.getUid());
        return userPasswordChangeCmdExo.execute(cmd);
    }

    @Override
    public Response changeNewEmail(EmailChangeCmd cmd) {
        return null;
    }
}
